package frsf.cidisi.exercise.modelo.util;

import java.awt.BorderLayout;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;


public class JPanelCelda extends JPanel {

	private static final long serialVersionUID = 1L;

	private Celda celda;
	
	private JPanel panelCentro;
	private JPanel panelNorte;
	private JPanel panelSur;
	private JPanel panelEste;
	private JPanel panelOeste;
	
	
	private final String IMAGES_PATH = "src/frsf/cidisi/exercise/modelo/resources/";
    private final String IMAGES_EXT = ".jpg";
    
    public JPanelCelda(Celda celda) {
		super();
		this.celda = celda;
		this.initCelda();
	}
    
    private void initCelda() {
		panelCentro = new JPanel();
		panelCentro.setLayout(new BorderLayout());
		panelNorte = new JPanel();
		panelNorte.setLayout(new BorderLayout());
		panelSur = new JPanel();
		panelSur.setLayout(new BorderLayout());
		panelEste = new JPanel();
		panelEste.setLayout(new BorderLayout());
		panelOeste = new JPanel();
		panelOeste.setLayout(new BorderLayout());
		
		setLayout(new BorderLayout());
		
		if(celda.isSalida() && celda.isCerrada()) 
			panelCentro.add(new JLabel(new ImageIcon(IMAGES_PATH + "salida-candado" + IMAGES_EXT)));
		else if(celda.isSalida() )
			panelCentro.add(new JLabel(new ImageIcon(IMAGES_PATH + "salida" + IMAGES_EXT)));
		else if(celda.hasLlave())
			panelCentro.add(new JLabel(new ImageIcon(IMAGES_PATH + "llave" + IMAGES_EXT)));
		else if(celda.isCerrada())
			panelCentro.add(new JLabel(new ImageIcon(IMAGES_PATH + "candado" + IMAGES_EXT)));
		else if(celda.isEntrada())
			panelCentro.add(new JLabel(new ImageIcon(IMAGES_PATH + "entrada" + IMAGES_EXT)));
		else
			panelCentro.add(new JLabel(new ImageIcon(IMAGES_PATH + "fondo" + IMAGES_EXT)));
		
		if(celda.getParedNorte())
			panelNorte.add(new JLabel(new ImageIcon(IMAGES_PATH + "x1" + IMAGES_EXT)));
		else
			panelNorte.add(new JLabel(new ImageIcon(IMAGES_PATH + "x0" + IMAGES_EXT)));
		
		if(celda.getParedEste())
			panelEste.add(new JLabel(new ImageIcon(IMAGES_PATH + "y1" + IMAGES_EXT)));
		else
			panelEste.add(new JLabel(new ImageIcon(IMAGES_PATH + "y0" + IMAGES_EXT)));
		
		if(celda.getParedSur())
			panelSur.add(new JLabel(new ImageIcon(IMAGES_PATH + "x1" + IMAGES_EXT)));
		else
			panelSur.add(new JLabel(new ImageIcon(IMAGES_PATH + "x0" + IMAGES_EXT)));
		
		if(celda.getParedOeste())
			panelOeste.add(new JLabel(new ImageIcon(IMAGES_PATH + "y1" + IMAGES_EXT)));
		else
			panelOeste.add(new JLabel(new ImageIcon(IMAGES_PATH + "y0" + IMAGES_EXT)));
		
		add(panelCentro, BorderLayout.CENTER);
		add(panelNorte, BorderLayout.NORTH);
		add(panelSur, BorderLayout.SOUTH);
		add(panelEste, BorderLayout.EAST);
		add(panelOeste, BorderLayout.WEST);
	}
}
